package com.sn.pw.config.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;


@Component
@RequiredArgsConstructor
public class MybatisPlusObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", new Date(), metaObject);
        // 获取token信息
        this.setFieldValByName("createBy", -1L, metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
        // 获取token信息
        this.setFieldValByName("updateBy", -1L, metaObject);
        // 获取token信息
        this.setFieldValByName("creator", "admin", metaObject);
        // 获取token信息
        this.setFieldValByName("updater", "admin", metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
        // 获取token信息
        this.setFieldValByName("updateBy", -1L, metaObject);
        // 获取token信息
        this.setFieldValByName("updater", "admin", metaObject);
    }
}
